#include "TestPanelForm.h"

#define BUTTON3_ID 3



TestPanelForm::TestPanelForm() {

	this->CreatedEvent.Register(this, &TestPanelForm::OnCreated);

	m_brush = CreateSolidBrush(RGB(0xff, 0xdd, 0xaa));
}



TestPanelForm::~TestPanelForm() {
	DeleteObject(m_brush);
}



void TestPanelForm::OnCreated(CreatedEventArgs& args) {

	this->SetSize(500, 400);

	m_panel.SetText(L"Panel");
	m_panel.SetSize(200, 100);
	m_panel.SetPosition(0, 0);
	m_panel.SetParent(*this);
	m_panel.Create();

	m_button1.SetText(L"Button1");
	m_button1.SetSize(100, 30);
	m_button1.SetPosition(10, 10);
	m_button1.SetParent(m_panel);
	m_button1.Create();

	m_button2.SetText(L"Button2");
	m_button2.SetSize(100, 30);
	m_button2.SetPosition(10, 40);
	m_button2.SetParent(m_panel);
	m_button2.Create();

	m_button3.SetText(L"Move the Panel");
	m_button3.SetSize(100, 30);
	m_button3.SetPosition(250, 0);
	m_button3.SetParent(*this);
	m_button3.SetID(BUTTON3_ID);
	m_button3.Create();
}



LRESULT TestPanelForm::WndProc(const WndMsg& msg) {

	if (msg.Message == WM_COMMAND) {

		if (msg.WParamHigh == BN_CLICKED) {

			if (msg.WParamLow == BUTTON3_ID) {

				unsigned int x;
				unsigned int y;
				m_panel.GetPosition(x, y);

				x = (x + 1) % 30;
				y = (y + 1) % 30;

				m_panel.SetPosition(x, y);
				return 0;
			}
		}
	}

	if (msg.Message == WM_CTLCOLORDLG) {
		return (LRESULT)m_brush;
	}

	return Form::WndProc(msg);
}